package main

import (
	"fmt"
	"encoding/json"
)

//https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/07.2.md

func main(){
	var s=`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`
	fmt.Println("json string = ",s)
	var f interface{}
	json.Unmarshal([]byte(s),&f)
	fmt.Println("unmarshal result: ",f)
	fmt.Printf("type %V\n",f)
	m:=f.(map[string]interface{})
	fmt.Printf("type %V\n",m)
	
	//通过断言的方式
	for k,v:=range m{
		fmt.Println("----------------")
		fmt.Println("key = ",k)
		fmt.Println("val = ",v)
		switch vv:=v.(type){
			case string:
			fmt.Println(k," is string ",vv)
			case int:
			fmt.Println(k," is int",vv)
			case float64:
			fmt.Println(k," is float64",vv)
			case []interface{}:
			for i,u:=range vv{
				fmt.Println("interface[] -- ",i,u)
			}
			default:
			fmt.Println(k,"is of a type i don't know how to handle")
		}
	}
	
}